<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html"
              encoding="utf-8"
              media-type="text/html"
              doctype-public="-//W3C//DTD HTML 4.01//EN"
              doctype-system="http://www.w3.org/TR/xtml4/strict.dtd" />

  <xsl:template match="/">
    <xsl:choose>
      <xsl:when test="//html">
        <xsl:apply-templates />
      </xsl:when>
      <xsl:otherwise>
        <html>
          <head>
            <xsl:call-template name="meta" />
            <title><xsl:value-of select="//head/title" /></title>
          </head>
          <body>
            <xsl:apply-templates select="content" />
          </body>
        </html>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="html">
    <html>
      <xsl:apply-templates select="head" />
      <xsl:apply-templates select="body" />
    </html>
  </xsl:template>

  <xsl:template match="html/head">
    <head>
      <xsl:call-template name="meta" />
      <script type="text/javascript">
        hash=document.location.hash.replace(/^#/,'');
        if(!hash||/^ixzz\w+(\?.*)?$/.test(hash)){Tynt=['ds7-OitvWr4kSladbi-bpO'];Tynt.i={ap:'Источник:'};if(hash)with(document.location)replace(href);}
        else{document.location.hash='';document.location.href=hash;}
      </script>
      <title><xsl:value-of select="title" /></title>
      <link rel="shortcut icon" href="{//urls/content}/img/favicon.ico" />
      <link rel="stylesheet" href="{//urls/content}/css/closure/css/dialog.css" type="text/css" />
      <link rel="stylesheet" href="{//urls/content}/css/closure/css/datepicker.css" type="text/css" />
      <link rel="stylesheet" href="{//urls/content}/css/closure/css/popupdatepicker.css" type="text/css" />
      <!--
      <link rel="stylesheet" href="http://closure-library.googlecode.com/svn/trunk/closure/goog/css/dialog.css" type="text/css" />
      <link rel="stylesheet" href="http://closure-library.googlecode.com/svn/trunk/closure/goog/css/datepicker.css" type="text/css" />
      <link rel="stylesheet" href="http://closure-library.googlecode.com/svn/trunk/closure/goog/css/popupdatepicker.css" type="text/css" />
      -->
      <link href="{//urls/content}/css/style.css" rel="stylesheet" type="text/css" />
    </head>
  </xsl:template>

  <xsl:template match="body">
    <body onload="fs.init();">
      <div class="body-block gray" id="header">
        <div id="rss">
          <a href="#" class="anchor gray">RSS</a>
        </div>
        <xsl:choose>
          <xsl:when test="//auth">
            <xsl:apply-templates select="//auth" />
          </xsl:when>
          <xsl:otherwise>
            <div id="auth">
              <a class="pseudo-link" href="#login">Войти</a>
              <span>или</span>
              <a class="pseudo-link" href="#">Зарегистрироваться</a>
            </div>
            <div class="invisible" id="auth-dlg" title="Вход">
              <form id="auth-form" action="{//urls/base}/user/login" method="post">
                <div class="field">
                  <label for="login">Логин:</label>
                  <input type="text" class="rounded required" id="login" name="user[login]" maxlength="100" />
                </div>
                <div class="field">
                  <label for="paswd">Пароль:</label>
                  <input type="password" class="rounded required" id="paswd" name="user[password]" />
                </div>
                <div class="field invisible" id="acode-field">
                  <label for="acode">Код активации:</label>
                  <input type="text" class="rounded" id="acode" name="acode" />
                </div>
                <a href="#" class="field" id="other-links">Войти, используя другие сервисы</a>
                <div class="field" id="other-login">
                  <a href="{//urls/base}/user/login" id="vk-login" />
                </div>
              </form>
            </div>
          </xsl:otherwise>
        </xsl:choose>
        <div id="republic-news">
          <div id="republic" title="Новости по республикам">
            <a href="#">
              <span class="pseudo-link">Выбрать</span>
            </a>
          </div>
          <span id="republic-name">Все республики</span>
          <div class="invisible" id="USSR" title="Бывшие республики СССР">
            <img src="{//urls/content}/img/USSR.gif" alt="" width="520" height="323" usemap="#republics" />
            <map name="republics">
              <area id="lithuania" shape="poly" href="#" alt="Литва" coords="40,75,44,73,51,70,49,61,50,56,58,69,60,76,59,83,48,84" />
              <area id="latvia" shape="poly" href="#" alt="Латвия" coords="59,83,60,75,57,66,50,56,66,55,67,60,64,68,71,68,74,80,66,86" />
              <area id="estonia" shape="poly" href="#" alt="Эстония" coords="73,83,73,77,70,67,68,60,67,54,76,55,86,64,86,74,80,77" />
              <area id="moldova" shape="poly" href="#" alt="Молдавия" coords="12,126,5,123,1,122,1,117,13,105,20,113,20,117" />
              <area id="belarus" shape="poly" href="#" alt="Белоруссия" coords="47,113,46,110,42,109,35,100,36,92,32,85,28,81,30,79,33,78,39,75,42,78,47,82,57,82,63,84,67,96,59,104,59,110,54,109" />
              <area id="ukraine" shape="poly" href="#" alt="Украина" coords="24,159,15,153,9,150,14,145,12,139,17,139,17,132,10,129,5,129,4,123,12,125,18,117,18,111,13,106,9,97,7,89,11,86,19,86,23,88,28,85,35,88,38,93,36,98,42,107,48,110,55,117,53,127,51,133,55,139,54,143,57,151,48,159,42,156,37,156,30,149,25,148,22,150" />
              <area id="armenia" shape="poly" href="#" alt="Армения" coords="23,230,26,225,28,222,27,216,28,212,28,208,23,204,20,201,15,205,15,209,17,214,20,215,23,217,22,224" />
              <area id="georgia" shape="poly" href="#" alt="Грузия" coords="28,208,31,208,32,215,35,212,35,208,39,203,32,197,32,193,24,177,20,177,20,186,14,192,15,198,20,201" />
              <area id="azerbaijan" shape="poly" href="#" alt="Азербайджан" coords="23,220,20,227,15,222,19,214,23,218,24,219,28,216,28,209,31,209,31,214,33,214,35,209,38,212,38,219,48,221,47,227,48,229,48,235,42,234,37,238,28,239,26,234,29,229,25,228,25,222" />
              <area id="kyrgyzstan" shape="poly" href="#" alt="Киргизия" coords="151,296,143,296,137,294,130,292,129,295,140,299,143,303,151,304,154,306,161,305,169,307,173,305,178,306,192,302,191,297,186,295,185,293,165,285,161,281,156,285,151,280,144,281,139,284,139,289,144,289" />
              <area id="tajikistan" shape="poly" href="#" alt="Таджикистан" coords="136,293,131,292,129,295,141,299,142,302,151,305,153,309,157,312,154,322,144,320,130,319,132,311,130,310,124,312,116,311,111,308,113,306,118,302,121,296,119,293,120,291,125,291,131,287,138,291" />
              <area id="uzbekistan" shape="poly" href="#" alt="Узбекистан" coords="112,309,120,299,121,295,120,292,121,289,125,291,132,287,139,290,138,293,144,296,150,296,145,290,141,290,139,287,142,282,135,281,129,284,127,280,123,277,122,271,126,267,124,266,125,261,121,258,118,257,113,253,108,251,108,245,101,232,90,226,75,247,78,251,82,248,90,248,95,254,93,259,99,265,98,275,109,295,109,301,106,304" />
              <area id="turkmenistan" shape="poly" href="#" alt="Туркменистан" coords="106,303,109,300,109,297,97,276,97,268,98,266,92,261,95,254,90,247,82,248,79,251,71,246,71,235,66,231,59,230,55,238,50,244,51,250,43,262,47,267,54,266,62,270,65,276,71,282,71,287,73,291,72,296,78,305,84,306,87,304,94,305,100,300" />
              <area id="kazakhstan" shape="poly" href="#" alt="Казахстан" coords="68,201,69,195,71,191,70,179,78,178,81,173,84,173,83,178,85,180,89,176,100,177,104,182,108,193,110,196,119,200,121,204,130,209,133,206,131,202,131,200,136,200,139,197,141,198,142,194,142,190,147,192,155,196,163,198,174,198,179,201,180,208,183,212,185,213,184,216,193,216,197,215,198,217,203,224,204,235,206,241,209,241,215,245,220,245,222,249,226,255,229,258,232,256,235,260,236,263,229,267,227,273,223,276,214,273,209,280,207,285,200,283,198,283,196,294,193,300,189,297,182,291,166,286,160,281,157,284,152,281,143,280,140,283,137,281,132,280,130,283,122,276,122,272,124,267,123,265,123,261,120,258,110,252,107,244,101,231,90,227,74,247,72,247,71,235,64,230,60,226,62,214,61,210,64,208,67,210,71,208,77,211,80,208,76,203" />
              <area id="russia" shape="poly" href="#" alt="Российская Федерация" coords="44,58,52,63,52,70,75,81,81,76,88,75,91,77,93,71,110,72,141,45,155,48,156,73,163,78,176,81,192,75,217,61,225,57,228,22,237,26,250,28,251,35,232,59,241,61,258,50,285,44,300,64,303,73,311,73,317,78,317,90,336,93,336,88,349,88,353,96,360,98,358,93,365,92,369,88,369,77,356,77,351,69,353,61,371,34,376,52,372,65,376,69,388,68,398,69,409,58,417,61,428,44,428,17,433,10,435,14,434,30,460,12,472,1,480,10,482,17,470,27,473,37,487,39,484,49,490,77,482,85,485,95,488,104,498,110,516,99,516,102,498,114,504,120,502,129,507,133,505,139,510,147,509,154,516,186,508,227,489,219,484,226,463,197,457,196,469,214,466,261,458,268,451,267,451,273,445,276,447,272,444,265,442,256,448,252,445,230,432,242,424,236,411,236,396,219,380,220,374,226,378,231,374,248,370,253,356,251,349,259,342,261,332,261,318,255,307,259,299,253,287,246,283,262,269,260,263,254,256,255,245,260,235,260,227,255,221,247,215,244,209,241,206,241,202,221,198,217,191,217,185,217,181,209,180,201,174,198,165,198,156,195,145,191,142,197,132,199,134,205,130,209,121,205,120,199,107,194,104,186,99,177,88,176,84,180,83,174,77,178,71,178,71,191,68,198,60,198,53,200,51,207,46,220,39,220,38,212,35,207,38,204,36,200,31,196,32,192,24,177,24,157,33,160,34,157,38,159,41,155,45,158,55,151,52,145,53,139,49,133,52,123,55,117,50,112,57,107,61,111,61,103,69,96,66,86,75,81,52,70,46,74,35,64" />
            </map>
          </div>
        </div>
        <div id="search-block">
          <input type="text" id="search-text" maxlength="200" />
          <button>Искать</button>
        </div>
      </div>
      <hr id="top-line" />
      <div class="body-block" id="body">
        <div id="logo">
          <h1>Территория свободы слова</h1>
          <div class="gray">Общественный информационно-аналитический портал</div>
          <xsl:call-template name="link">
            <xsl:with-param name="url"><xsl:value-of select="concat(//urls/base, '/site/contacts')" /></xsl:with-param>
            <xsl:with-param name="text">Свидетельство о регистрации СМИ № ФС77-43020 от 15 декабря 2010 г.</xsl:with-param>
            <xsl:with-param name="class">gray</xsl:with-param>
          </xsl:call-template>
        </div>
        <div id="menu-block">
          <div id="informers">
            <xsl:call-template name="gismeteo">
              <xsl:with-param name="code">4368</xsl:with-param>
              <xsl:with-param name="city">Москва</xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="gismeteo">
              <xsl:with-param name="code">4944</xsl:with-param>
              <xsl:with-param name="city">Киев</xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="gismeteo">
              <xsl:with-param name="code">4248</xsl:with-param>
              <xsl:with-param name="city">Минск</xsl:with-param>
            </xsl:call-template>
            <xsl:call-template name="gismeteo">
              <xsl:with-param name="code">5164</xsl:with-param>
              <xsl:with-param name="city">Астана</xsl:with-param>
            </xsl:call-template>
          </div>
          <xsl:apply-templates select="menu" />
        </div>
        <div id="handling">
          <div class="editor-photo rounded shadow" />
          <div class="gray">
            <h3>От главного редактора</h3>
            <a href="{//urls/base}/site/handling" class="anchor black link">Вы находитесь на общественном информационно-аналитическом портале freesmi.ru...</a>
          </div>
        </div>
        <div id="content-body">
          <div class="block" id="rubric-block">
            <xsl:apply-templates select="rubrics" />
            <br />
            <xsl:apply-templates select="autors" />
            <xsl:apply-templates select="banners" />
          </div>
          <div id="content-blocks">
            <div id="content-block">
              <div id="content">
                <xsl:apply-templates select="content" />
              </div>
              <xsl:apply-templates select="clouds" />
              <div class="block" id="group-block">
                <div class="header"><span class="gray">Мы в социальных сетях</span></div>
                <div id="vk_groups" />
              </div>
            </div>
            <div id="charity">
              <div class="block" id="charity-block">
                Если вы имеете возможнось (и желание) оказать финансовую поддержку проекту, способы передачи денег:
              </div>
              <div class="block money">
                <p class="logo" id="wm">WebMoney:</p>
                <ul>
                  <li>WMR: R127618255908</li>
                  <li>WME: E340381528116</li>
                  <li>WMZ: Z348499588939</li>
                </ul>
              </div>
              <div class="block money">
                <p class="logo" id="ya">Яндекс-кошелек:</p>
                <p>41001123615022</p>
              </div>
              <div class="block money">
                <p class="logo" id="sb">расчетный счет:</p>
                <p>40817810738092314146</p>
              </div>
            </div>
          </div>
        </div>
      </div>
      <hr class="gray" id="bottom-line" />
      <div class="body-block" id="footer">
        <a href="{//urls/home}" class="anchor black" id="home">www.freesmi.ru</a>
      </div>
      <iframe class="invisible" id="ajax-content" src="about:blank" />
      <script type="text/javascript" src="http://tcr.tynt.com/ti.js" async="async"></script>
      <script type="text/javascript" src="{//urls/content}/js/cl/closure/goog/base.js" />
      <!--script type="text/javascript" src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js" /-->
      <script type="text/javascript" src="http://userapi.com/js/api/openapi.js" />
      <script type="text/javascript" src="{//urls/content}/js/main.js" />
    </body>
  </xsl:template>

  <xsl:template name="meta">
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
    <meta http-equiv="Content-Language" content ="ru" />
  </xsl:template>

  <xsl:template name="gismeteo">
    <xsl:param name="code" />
    <xsl:param name="city" />
    <a href="http://www.gismeteo.ru/city/daily/{$code}/" target="_blank">
      <img src="http://informer.gismeteo.ru/new/{$code}-13.GIF" alt="{$city} (GISMETEO)" title="GISMETEO: Погода по г.{$city}" />
    </a>
  </xsl:template>

  <xsl:template name="link">
    <xsl:param name="url" />
    <xsl:param name="text" />
    <xsl:param name="class" />
    <a>
      <xsl:choose>
        <xsl:when test="$url=//urls/active">
          <xsl:attribute name="class"><xsl:value-of select="concat($class, ' active link')" /></xsl:attribute>
          <xsl:attribute name="url"><xsl:value-of select="$url" /></xsl:attribute>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="class"><xsl:value-of select="concat($class, ' link')" /></xsl:attribute>
          <xsl:attribute name="href"><xsl:value-of select="$url" /></xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
      <xsl:value-of select="$text" />
    </a>
  </xsl:template>

  <xsl:template name="profile-link">
    <xsl:param name="text" />
    <xsl:param name="class" />
    <xsl:param name="img" />
    <xsl:call-template name="link">
      <xsl:with-param name="url"><xsl:value-of select="concat(//urls/base, '/user/profile/', @login)" /></xsl:with-param>
      <xsl:with-param name="text"><xsl:value-of select="$text" /></xsl:with-param>
      <xsl:with-param name="class"><xsl:value-of select="$class" /></xsl:with-param>
    </xsl:call-template>
  </xsl:template>

  <xsl:template match="menu">
    <ul id="menu">
      <xsl:apply-templates select="item" />
    </ul>
  </xsl:template>

  <xsl:template match="menu/item">
    <li>
      <xsl:call-template name="link">
        <xsl:with-param name="url"><xsl:value-of select="@href" /></xsl:with-param>
        <xsl:with-param name="text"><xsl:value-of select="." /></xsl:with-param>
        <xsl:with-param name="class">anchor black</xsl:with-param>
      </xsl:call-template>
    </li>
  </xsl:template>

  <xsl:template match="rubrics">
    <div class="header"><span class="gray">Разделы</span></div>
    <ul id="rubrics">
      <xsl:apply-templates select="rubric" />
      <li><hr class="gray" /></li>
    </ul>
    <div class="invisible" id="respublica">
      Рубрика <strong>RES PUBLICA</strong> (с <em>лат.</em> буквально - <b>&#171;общее дело&#187;</b>)
      предназначена для всевозможных материалов (тексты, видео, документы, фото), которые можно охарактеризовать термином
      <em>&#171;журналистское(гражданское) расследование&#187;</em>
      <br />
      Мы надеемся, что большинство публикаций размещенных здесь вызовут адекватный общественный резонанс и, таким образом,
      контент данной рубрики будет качественно увеличиваться по-принципу &#171;снежного кома&#187;
      <br />
      <small class="gray">
        <em>Для того чтобы ваши материалы попали в <strong>RES PUBLICA</strong>, они должны быть одобрены модератором.</em>
      </small>
    </div>
    <div class="invisible" id="diaspora">
      События их жизни русской иммиграции в <em>Америке</em>, <em>Евросоюзе</em>, <em>Израиле</em>
    </div>
  </xsl:template>

  <xsl:template match="rubrics/rubric">
    <li id="rubric{@id}">
      <xsl:if test="tags">
        <xsl:attribute name="class">group</xsl:attribute>
      </xsl:if>
      <span class="rubric-exp" />
      <a href="#"><xsl:value-of select="name" /></a>
      <xsl:apply-templates select="tags" />
    </li>
  </xsl:template>

  <xsl:template match="rubric/tags">
    <ul class="group">
      <xsl:apply-templates select="tag" />
    </ul>
  </xsl:template>

  <xsl:template match="rubric/tags/tag">
    <li>
      <a href="#" class="anchor"><xsl:value-of select="." /></a>
    </li>
  </xsl:template>

  <xsl:template match="autors">
    <div class="header"><span class="gray">Авторы</span></div>
    <ul id="autors">
      <xsl:apply-templates select="category" />
    </ul>
  </xsl:template>

  <xsl:template match="category">
    <li class="group">
      <span class="rubric-exp" />
      <a href="#"><xsl:value-of select="@name" /></a>
      <ul class="group">
        <xsl:apply-templates select="autor" />
      </ul>
    </li>
  </xsl:template>

  <xsl:template match="autor">
    <li>
      <xsl:call-template name="profile-link">
        <xsl:with-param name="text"><xsl:value-of select="." /></xsl:with-param>
        <xsl:with-param name="class">anchor</xsl:with-param>
      </xsl:call-template>
    </li>
  </xsl:template>

  <xsl:template match="banners">
    <a href="http://www.rospil.info" target="blank">
      <img src="{//urls/content}/banners/rospil.gif" class="banner" alt="РосПил" />
    </a>
  </xsl:template>

  <xsl:template match="clouds">
    <div class="block" id="tag-block">
      <div class="header">
        <span class="gray">Метки</span>
        <a href="#" class="pseudo-link" id="calendar">Выбрать дату</a>
      </div>
      <div id="clouds">
        <xsl:apply-templates select="rubric" />
        <xsl:apply-templates select="tag" />
      </div>
    </div>
  </xsl:template>

  <xsl:template match="clouds/rubric|clouds/tag">
    <a href="#" class="anchor gray" style="font-size:{round(10 + 24 * number(@count) div number(../@total))}px;">
      <xsl:value-of select="name" />
    </a>
    <xsl:text> </xsl:text>
  </xsl:template>

</xsl:stylesheet>
